#pragma once
#include"noncopyable.h"
#include"Socket.h"
#include<functional>
#include"Channel.h"
class EventLoop;
class InetAddress;
class Acceptor:noncopyable
{
public:
    using NewConnectionCallback = std::function<void(int sockfd,const InetAddress&)>;
    Acceptor(EventLoop* loop,const InetAddress& listenAddr,bool reuseport);
    ~Acceptor();

    void setNewConnectioCallback(const NewConnectionCallback& cb)
    {
        newConnectionCallback_ = cb;
    }

    bool listening() const{return listenning_;}
    void listen();
private:
    void handleRead();

    EventLoop* loop_; // Acceptor 用的就是用户定义的baseLoop，也是mainLoop
    Socket acceptSocket_;
    Channel acceptChannel_; // TcpConnection 一样的作用
    NewConnectionCallback newConnectionCallback_;
    bool listenning_;
};